import { baseUrl } from "../config/env";
import axios from "axios";
/**
 * 获取地图数据
 * @param {*} start
 * @param {*} end
 * @param {*} result
 */
export function getMap(start, end, result) {
  axios
    .get(baseUrl + "/grad/org_location" + "?start=" + start + "&end=" + end)
    .then((res) => {
      if (res.data.code == 1) {
        let bachelor = res.data.data.bachelor;
        let master = res.data.data.master;
        let arr = [];
        for (let i = 0; i < bachelor.length; i++) {
          for (let j = 0; j < master.length; j++) {
            if (bachelor[i].term == master[j].term) {
              arr.push({
                name: bachelor[i].term,
                value: bachelor[i].num + master[j].num,
              });
            }
          }
        }
        result(arr);
      } else {
        console.log("error");
      }
    })
    .catch((res) => {
      console.log(res);
    });
}
/**
 * 获取首页折线图数据-毕业生就业率和毕业生数量
 * @param {*} result
 */
export function getBroken(result) {
  return axios
    .get(baseUrl + "/grad/rate")
    .then((res) => {
      if (res.data.code == 1) {
        result(res.data.data.bachelor, res.data.data.master);
      }
    })
    .catch((res) => {
      console.log(res);
    });
}

/**
 * 获取柱状图数据-单位性质
 * @param {*} start
 * @param {*} end
 * @param {*} result
 */
export function getBar(start, end, result) {
  axios
    .get(baseUrl + "/grad/org_kind" + "?start=" + start + "&end=" + end)
    .then((res) => {
      if (res.data.code == 1) {
        let bachelor = res.data.data.bachelor;
        let master = res.data.data.master;
        let arr = [];
        for (let i = 0; i < bachelor.length; i++) {
          for (let j = 0; j < master.length; j++) {
            if (bachelor[i].term == master[j].term) {
              arr.push({
                name: bachelor[i].term,
                value: bachelor[i].num + master[j].num,
              });
            }
          }
        }

        let temp = arr[0];
        arr[0] = arr[arr.length - 1];
        arr[arr.length - 1] = temp;

        result(arr);
      } else {
        console.log("error");
      }
    })
    .catch((res) => {
      console.log(res);
    });
}

/**
 * 获得首页招聘信息
 * @param {} pageCount
 * @param {*} size
 * @param {*} result
 */
export function getRecruit(pageCount, size, result) {
  axios
    .get(
      baseUrl +
        "/recruitment/home" +
        "?pageCount=" +
        pageCount +
        "&size=" +
        size
    )
    .then((res) => {
      if (res.data.code == 1) {
        result(res.data.data.list);
      } else {
        console.log("error");
      }
    })
    .catch((res) => {
      console.log(res);
    });
}

/**
 * 获得饼图——热门城市
 * @param {*} result
 */
export function getPie(result) {
  axios
    .get(baseUrl + "/grad/city")
    .then((res) => {
      if (res.data.code == 1) {
        result(res.data.data);
      } else {
        console.log("error");
      }
    })
    .catch((res) => {
      console.log(res);
    });
}
